package com.whalehearing.tingyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whalehearing.tingyou.common.utils.StringUtils;
import com.whalehearing.tingyou.domain.HearingInitialValuation;
import com.whalehearing.tingyou.mapper.HearingInitialValuationMapper;
import com.whalehearing.tingyou.service.IHearingInitialValuationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 测前初评Service业务层处理
 *
 * @author zengjun-qxm
 * @date 2024-09-14
 */
@Service
public class HearingInitialValuationServiceImpl extends ServiceImpl<HearingInitialValuationMapper, HearingInitialValuation> implements IHearingInitialValuationService {

    @Autowired
    private HearingInitialValuationMapper hearingInitialValuationMapper;

    /**
     * 查询测前初评列表
     *
     * @param hearingInitialValuation 测前初评
     * @return 测前初评
     */
    @Override
    public List<HearingInitialValuation> selectHearingInitialValuationList(HearingInitialValuation hearingInitialValuation) {
        List<HearingInitialValuation> hearingInitialValuationList = hearingInitialValuationMapper.selectList(buildQueryWrapper(hearingInitialValuation));
        return hearingInitialValuationList;
    }


    private LambdaQueryWrapper<HearingInitialValuation> buildQueryWrapper(HearingInitialValuation query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<HearingInitialValuation> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(query.getNickName()), HearingInitialValuation::getNickName, query.getNickName());
        lqw.orderByDesc(HearingInitialValuation::getCreateTime);
        return lqw;
    }

    /**
     * 根据-userId-查询用户测前初评列表
     */
    @Override
    public List<HearingInitialValuation> getInitialValuationListByUserId(Long userId) {
        QueryWrapper<HearingInitialValuation> wrapper = new QueryWrapper<HearingInitialValuation>()
                .eq("user_id", userId).orderByDesc("create_time");
        return hearingInitialValuationMapper.selectList(wrapper);
    }


}
